Ext.define('DutyList.calendar.dd.DragZonCalendarPanel', {
    extend: 'Ext.dd.DragZone',
    requires: [
        'DutyList.calendar.dd.StatusProxy',
        'DutyList.calendar.data.SheduleMappings'
    ],

    eventSelector: '.ext-cal-evt',

    constructor: function(el, config) {
        if (!DutyList.calendar._statusProxyInstance) {
            DutyList.calendar._statusProxyInstance = new DutyList.calendar.dd.StatusProxy();
        }
        this.proxy = DutyList.calendar._statusProxyInstance;
        this.callParent(arguments);
    },

    getDragData: function(e) {
        // Check whether we are dragging on an event first
        var t = e.getTarget(this.eventSelector, 3);
        if (t) {
            var rec = this.view.getSheduleRecordFromEl(t);
            return {
                type: 'eventdrag',
                ddel: t,
                startDate: rec.data[DutyList.calendar.data.SheduleMappings.StartDate.name],
                proxy: this.proxy
            };
        }
        return null;
    },
    onInitDrag: function(x, y) {
        if (this.dragData.ddel) {
            var ghost = this.dragData.ddel.cloneNode(true),
                child = Ext.fly(ghost).down('dl');
            Ext.fly(ghost).setWidth('auto');
            if (child) {
                // for IE/Opera
                child.setHeight('auto');
            }
            this.proxy.update(ghost);
            this.onStartDrag(x, y);
        }
        this.view.onInitDrag();
        return true;
    },
    afterRepair: function() {
        Ext.fly(this.dragData.ddel).highlight(this.hlColor || 'c3daf9');
        this.dragging = false;
    },

    getRepairXY: function(e) {
        if (this.dragData.ddel) {
            return Ext.fly(this.dragData.ddel).getXY();
        }
    },

    afterInvalidDrop: function(e, id) {
        Ext.select('.ext-dd-shim').hide();
    }
});
